import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getList(this);
		},
		//获取列表
		getList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {businessType:130};
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'post',
					url:apiTest+'/supplier/whWarehouse/list',
					data:{
						condition:params,
						pageIndex: pageIndex,
						pageSize: pageSize,
					}
			    }).then((res)=>{
					that.Model.tableData = [];
					var data = res.data;
					if(data.status == 200){
						var obj = {};
						var pagination = commonObject.paginationFunction(data.result);
						that.Model.paginationObject = objDeepCopy(pagination);
						var result = data.result.result;
						if(result){
							for (var i = 0; i < result.length; i++) {
								obj = objDeepCopy(result[i]);
								if(result[i].typeDict){
									obj.remarkType = result[i].typeDict.value;
								}
								if(result[i].statusDict){
									obj.showStatus = result[i].statusDict.value;
								}
								that.Model.tableData.push(obj)
							}
						}
					}else{
			
					}
				});
		},
		
		//新建调拨单
		newPage(){
			this.$router.push({
				path:'certificationSheetListNew',
				query:{
					
				}
			});
		},
		// 点击导入国检数据
		importNiData(){
			this.Model.importFileDialog = true;
		},
		//选择文件
		fileChange(){
			var fileObj = document.getElementById("fileup").files[0];
			var form = new FormData();
			form.append("file", fileObj);
			this.Model.upFileForm = form;
			var that = this;
			var obj = document.getElementById("fileup");
			var len = obj.files.length;
			for (var i = 0; i < len; i++) {
				var temp = obj.files[i].name;
				that.Model.fileupName = temp;
			}
		},
		//点击上传
		uploadExcel(){
			var apiTest = this.apiTest;
			var tableData = objDeepCopy(this.Model.tableData);
			var that = this;
			this.$ajax({
				method: 'post',
				url:apiTest+'/supplier/whWarehouse/importInspectionData',
				data:that.Model.upFileForm
			}).then((res)=>{
				console.log(res);
				var obj = {};
				if(res.data.status == 200){
					var result = res.data.result;
					that.tips(that,'success','导入成功')
					// that.tips(that,'success','导入成功！')
					setTimeout(function(){
						that.Model.importFileDialog = false;
					},1000);
				}else{
					that.tips(that,'warning',data.msg)
				}
			});
		},
		//下载模板(假的)
		downloadExcel(){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'get',
				url:apiTest+'/supplier/whWarehouseDetail/getGoodsExcelInfo',
			}).then((res)=>{
				console.log(res);
				if(res.data.status == 200){
					var result = res.data.result;
					if(result.fileUrl){
						window.open(result.fileUrl);
					}
					
				}else{
					
				}
			});
		},
		//详情
		toDetial(row) {
			this.$router.push({
				path:'certificationSheetListDetail',
				query:{
					number:row.number
				}
			});
		},
		//作废 或者 制证出库
		orderObsolete(row,type) {
			if(type == 'obsolete'){
				this.$confirm('作废后，则无法再对该单进行操作，是否确定作废?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
					this.obsoleteAjax(this,130,row.id);
				}).catch(() => {
					
				});
				
			}else if(type == 'out'){
				this.$confirm('制证出库后，则无法再对该单进行操作，是否确定制证出库?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
					this.outAjax(this,row.id);
				}).catch(() => {
				           
				});
			}
			
		},
		//作废 ajax
		obsoleteAjax(that,businessType,id){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'get',
				url:apiTest+'/supplier/whWarehouse/cancel/'+businessType+'/'+id,
			}).then((res)=>{
				console.log(res);
				if(res.data.status == 200){
					var result = res.data.result;
					that.tips(that,'success','操作成功')
					that.getList(that);
				}else{
					that.tips(that,'warning',data.msg)
				}
			});
		},
		//制证出库 ajax
		outAjax(that,id){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'get',
				url:apiTest+'/supplier/whWarehouse/updateAuthOut/'+id,
			}).then((res)=>{
				console.log(res);
				if(res.data.status == 200){
					var result = res.data.result;
					that.tips(that,'success','操作成功')
					that.getList(that);
				}else{
					that.tips(that,'warning',data.msg)
				}
			});
		},
		
		//打开 编辑页
		orderEdit(row){
			this.$router.push({
				path:'certificationSheetListEdit',
				query:{
					id:row.id,
					number:row.number
				}
			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			console.log(val);
			this.Model.addGiftsSelectData = val
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,val);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
		  console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		statusFilters:function(value){
			var val;
			switch (value){
				case 10:val = '待制证'
					break;
				case 20:val = '制证中'
					break;
				case 30:val = '已制证'
					break;
				case 40:val = '已完结'
					break;
				case 50:val = '已作废'
					break;
				default:
					break;
			}
		}
	}
}
export default Controller;
